<!--
 * @Author: HeAo
 * @Date: 2021-10-12 10:04:03
 * @LastEditTime: 2021-10-12 10:16:16
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day04\4-动态组件.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <div class="btns">
      <button @click="isAcvice = 'my-com1'">组件一</button>
      <button @click="isAcvice = 'my-com2'">组件二</button>
    </div>
    <!-- <my-com1 v-if="isAcvice"></my-com1>
    <my-com2 v-else></my-com2> -->
    <keep-alive>
      <component :is="isAcvice"></component>
    </keep-alive>
  </div>
  <script>
    let component1 = {
      data() {
        return {

        }
      },
      template: `
        <div>
          <h1>我是组件一</h1>
        </div>
      `,
      created() {
        console.log('组件一被创建');
      }
    }

    let component2 = {
      data() {
        return {

        }
      },
      template: `
        <div>
          <h1>我是组件二</h1>
        </div>
      `,
      created() {
        console.log('组件二被创建');
      }
    }

    let vm = new Vue({
      el: '#app',
      data: {
        isAcvice: '',
        myCom1: 'my-com1'
      },
      methods: {},
      components: {
        myCom1: component1,
        myCom2: component2,
      }
    })
  </script>
</body>

</html>